#include "common.h"

vector<vector<int>> ans;
vector<int> temp;
int flg[8] = { 0 };
void dfs(vector<int>& nums)
{
	if (nums.size() == temp.size())
	{
		ans.push_back(temp);
		return;
	}

	for (int i = 0; i < nums.size(); i++)
	{
		if (flg[i] == 0 && (i == 0 || nums[i] != nums[i - 1] || flg[i - 1] == 1))
		{
			temp.push_back(nums[i]);
			flg[i] = 1;
			dfs(nums);
			temp.pop_back();
			flg[i] = 0;
		}
	}
}
vector<vector<int>> permuteUnique(vector<int>& nums)
{
	sort(nums.begin(), nums.end());
	dfs(nums);
	return ans;
}